package com.fann;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class regServlet
 */
public class RegServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegServlet() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String userid = "";
		String nickname = "";
		String pw1 = "";
		String pw2 = "";
		String email = "";
		
		if (request.getParameter("userid") != null){
			
			userid = request.getParameter("userid");
			nickname = request.getParameter("nickname");
			pw1 = request.getParameter("pw1");
			pw2 = request.getParameter("pw2");
			email = request.getParameter("email");
			
			//Construction
			Member m = new Member(userid, nickname, pw1, pw2, email);
			
			//Set session
			HttpSession session = request.getSession();
			session.setAttribute("m", m);
			
			//register Success, Fail
			if (m.registerValidate()){
				response.sendRedirect("registerComplete.jsp");
			} else {
				response.sendRedirect("register.jsp");
			}
		}
	}

}
